package com.rock.code.common.aspect;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * The type Option log aspect.
 *
 * @author kongqiang
 * @date 2018 /02/08
 */
public class OptionLogAspect {



    /**
     * Before advice: 前置通知.
     *
     * @param jp the jp
     * @author kongqiang
     * @date 2018 /02/08
     */
    public void beforeAdvice(JoinPoint jp) {
//        System.out.println("前置通知执行了");
    }

    /**
     * After advice: 后置通知.
     *
     * @param jp the jp
     * @author kongqiang
     * @date 2018 /02/08
     */
    public void afterAdvice(JoinPoint jp) {
//        System.out.println("后置通知执行了");
    }

    /**
     * After return advice: 返回通知.
     *
     * @param jp     the jp
     * @param result the result
     * @author kongqiang
     * @date 2018 /02/08
     */
    public void afterReturnAdvice(JoinPoint jp, Object result) {
        System.out.println(jp.getTarget().getClass().getName());
    }

    /**
     * Around advice object: 环绕通知.
     *
     * @param pjp the proceeding join point
     * @return the object
     * @throws Throwable the throwable
     * @author kongqiang
     * @date 2018 /02/08
     */
    public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
        Object result = null;
//        long start = System.currentTimeMillis();
        result = pjp.proceed();
//        long end = System.currentTimeMillis();
//        System.out.println("执行耗时：" + (end - start) + "毫秒。");
        return result;
    }

    /**
     * Throwing advice: 异常通知.
     *
     * @param jp the jp
     * @param e  the e
     * @author kongqiang
     * @date 2018 /02/08
     */
    public void throwingAdvice(JoinPoint jp, Exception e) {
//        StringBuffer stringBuffer = new StringBuffer();
//        stringBuffer.append("方法:").append(jp.getSignature().getName()).append("出现了异常.");
//        stringBuffer.append("异常信息为:").append(e.getMessage());
//        System.out.println(stringBuffer.toString());
    }
}
